package com.nmf.pc.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.nmf.site.biz.pay.wechat.entity.TenOpenVo;
import com.nmf.site.biz.pay.wechat.service.WechatJsWebPay;
@Controller
@RequestMapping("pc")
public class WechatActokenController {
	Logger log = LoggerFactory.getLogger(WechatActokenController.class);
	@Autowired
	WechatJsWebPay wechatJsWebPay;
	/**
	 * 微信端逻辑
	 * @param orderNo
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping(value = "p/v1.0/oauthUrl", method = RequestMethod.GET)
	public void wechatAuth(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		String rurl = wechatJsWebPay.createWebOauthUrlForCode();
		log.info(rurl);
		response.sendRedirect(rurl);
	}
	
	/**
	 * 微信端逻辑
	 * @param orderNo
	 * @param code
	 * @param model
	 * @param redirectAttributes
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	//支付 H5呼起支付
	@RequestMapping(value = "p/v1.0/wchatcode", method = RequestMethod.GET)
	@ResponseBody
	public TenOpenVo payAccount(@RequestParam(required=true) String orderNo,@RequestParam(required=true) String code,Model model,  RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response) throws IOException {
		TenOpenVo tenOpenVo = wechatJsWebPay.getOpenId(code);
		return tenOpenVo;
	}
	
	
	
}
